package com.qf.common.config;

/**
 * @author zdl
 * @date 2025/3/12
 */
import com.qf.common.job.SendVerificationCodeJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail sendVerificationCodeJobDetail() {
        return JobBuilder.newJob(SendVerificationCodeJob.class)
                .withIdentity("sendVerificationCodeJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger sendVerificationCodeJobTrigger() {
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(60) // 每 60 秒执行一次
                .repeatForever();

        return TriggerBuilder.newTrigger()
                .forJob(sendVerificationCodeJobDetail())
                .withIdentity("sendVerificationCodeTrigger")
                .withSchedule(scheduleBuilder)
                .build();
    }
}
